package com.example.campuspass.service;

import com.example.campuspass.entity.Student;
import com.example.campuspass.mapper.StudentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service // 重要！标记这是一个Spring的业务Bean
public class StudentServiceImpl implements StudentService {

    @Autowired // 自动注入Mapper组件
    private StudentMapper studentMapper;

    @Override
    public boolean saveStudentInfo(Student student) {
        // 在实际项目中，这里可以添加业务逻辑，如数据校验、重复学号检查等
        try {
            int result = studentMapper.insertStudent(student);
            return result > 0; // 如果插入行数大于0，返回成功
        } catch (Exception e) {
            // 记录日志，处理异常
            return false;
        }
    }

    @Override
    public List<Student> getStudentsByClass(String className) {
        return studentMapper.selectStudentsByClassName(className);
    }

    @Override
    public Student getStudentByNumber(String studentNumber) {
        return studentMapper.selectStudentByNumber(studentNumber);
    }
}
